import * as types from '../types';
import Vue from 'vue';

const state = {
    top10List:[]
}
const actions = {
    //获取热门电影
    getMovieTop10:function({commit}){
       commit(types.GET_MOVIE_TOP_10_LIST);
    }
}
const getters = {
    getMovieTop10: state => state.top10List
}

const mutations = {
    [types.GET_MOVIE_TOP_10_LIST](state,res){
    	Vue.http.jsonp('https://api.douban.com/v2/movie/top250?count=10', {}, {
        headers: {

        },
        emulateJSON: true
    }).then(function(response) {
      	// 这里是处理正确的回调
		state.top10List = response.data.subjects;
        // this.articles = response.data["subjects"] 也可以

    }, function(response) {
        // 这里是处理错误的回调
        console.log(response)
    });
        
    }
}

export default {
    state,
    actions,
    getters,
    mutations
}